﻿// Copyright (c) Brock Allen & Dominick Baier. All rights reserved.
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.


using Bit.Art.Sso.Db;
using IdentityModel;
using IdentityServer4;
using IdentityServer4.Models;
using Microsoft.AspNetCore.Identity;
using System.Collections.Generic;

namespace Bit.Art.Sso
{
    public static class Config
    {
        public static IEnumerable<IdentityResource> GetIdentityResources()
        {
            return new IdentityResource[]
            {
                new IdentityResources.OpenId(),
                new IdentityResources.Profile(),
            };
        }

        public static IEnumerable<ApiResource> GetApis()
        {
            return new ApiResource[]
            {
                new ApiResource("market", "Market API", new string[] { JwtClaimTypes.PhoneNumber }),
                new ApiResource("account", "Deposit & Withdraw API", new string[] { JwtClaimTypes.PhoneNumber }),
                new ApiResource("partner", "APIs for partner", new string[] { JwtClaimTypes.ClientId })
            };
        }

        public static IEnumerable<Client> GetClients()
        {
            return new[]
            {
                new Client
                {
                    ClientId = "swaggerui",
                    ClientName = "Swagger UI",
                    AllowedGrantTypes = GrantTypes.Implicit,
                    AllowAccessTokensViaBrowser = true,
                    // o2c.html已经更换成oauth2-redirect.html
                    // 参考文档：https://github.com/domaindrivendev/Swashbuckle.AspNetCore/issues/642
                    RedirectUris = { "http://leyou.586886.com/swagger/oauth2-redirect.html" },
                    PostLogoutRedirectUris = { "http://leyou.586886.com/swagger/" },

                    AllowedScopes = { "market", "account" }
                },

                new Client
                {
                    ClientId = "js",
                    ClientName = "JavaScript Client",
                    AllowedGrantTypes = GrantTypes.Implicit,
                    AllowAccessTokensViaBrowser = true,
                    RequireConsent = false,

                    RedirectUris = { "http://leyou.586886.com/callback.html" },
                    PostLogoutRedirectUris = { "http://leyou.586886.com/index.html" },
                    AllowedCorsOrigins = { "http://leyou.586886.com" },

                    AllowedScopes =
                    {
                        IdentityServerConstants.StandardScopes.OpenId,
                        IdentityServerConstants.StandardScopes.Profile,
                        "market",
                        "account"
                    }
                },

                new Client
                {
                    ClientId = "debugjs",
                    ClientName = "JavaScript Debug Client",
                    AllowedGrantTypes = GrantTypes.Implicit,
                    AllowAccessTokensViaBrowser = true,
                    RequireConsent = false,

                    RedirectUris = { "http://localhost:5003/callback.html" },
                    PostLogoutRedirectUris = { "http://localhost:5003/index.html" },
                    AllowedCorsOrigins = { "http://localhost:5003" },

                    AllowedScopes =
                    {
                        IdentityServerConstants.StandardScopes.OpenId,
                        IdentityServerConstants.StandardScopes.Profile,
                        "market",
                        "account"
                    }
                },

                new Client
                {
                    ClientId = "artapi",
                    ClientSecrets =
                    {
                        new Secret("=Gz}U?M^=9jeg.x'".Sha256())
                    },
                    ClientName = "Art Api",
                    AllowedGrantTypes = GrantTypes.ResourceOwnerPassword,
                    AllowedScopes = 
                    { 
                        IdentityServerConstants.StandardScopes.OpenId,
                        IdentityServerConstants.StandardScopes.Profile,
                        "market",
                        "account",
                        "partner" 
                    }
                },

                new Client
                {
                    ClientId = "artapi-debug",
                    ClientSecrets =
                    {
                        new Secret("5%]_67XBZ\\&Wrc_".Sha256())
                    },
                    ClientName = "Art Api Debug Version",
                    AllowedGrantTypes = GrantTypes.ResourceOwnerPassword,
                    AllowedScopes =
                    {
                        IdentityServerConstants.StandardScopes.OpenId,
                        IdentityServerConstants.StandardScopes.Profile,
                        "market",
                        "account",
                        "partner"
                    }
                },

                new Client
                {
                    ClientId = "leyou",
                    ClientSecrets = 
                    {
                        new Secret("1eYou@8*93".Sha256())
                    },
                    ClientName = "乐游网络科技",
                    AllowedGrantTypes = GrantTypes.ClientCredentials,
                    AllowedScopes = { "partner" }
                },

                new Client
                {
                    ClientId = "siyecao",
                    ClientSecrets =
                    {
                        new Secret("Pass123$".Sha256())
                    },
                    ClientName = "四叶草",
                    AllowedGrantTypes = GrantTypes.ClientCredentials,
                    AllowedScopes = { "partner" }
                }
            };
        }
    }
}
